using System;
using System.Collections.Generic;
using System.Text;

namespace Studio.Game.GameBox
{
    /// <summary>
    /// The keytree class, the core datatype enable faster searching airthmetic
    /// </summary>
    public class KeyTreeNode<T> : Dictionary<char, KeyTreeNode<T>>
    {

        public KeyTreeNode() : base() { _IsLeaf = false; }

        private T _Data;
        /// <summary>
        /// node data
        /// </summary>
        public T Data
        {
            get { return _Data; }
            set { _Data = value; }
        }

        private bool _IsLeaf;
        /// <summary>
        /// is leaf node? 
        /// the leaf is not the traditional leaf in a tree.
        /// it means a word is recognized in the node!
        /// </summary>
        public bool IsLeaf
        {
            get { return _IsLeaf; }
            set { _IsLeaf = value; }
        }

        /// <summary>
        /// Children pointers
        /// </summary>
        public new KeyTreeNode<T> this[char Key]
        {
            get 
            {
                if (base.ContainsKey(Key))
                    return base[Key];
                else
                    return null;
            }

            set
            {   
                // Remove exist child first if necessary.
                base.Remove(Key);
                base.Add(Key, value);
            }
        }
    }
}
